from typing import List


class Solution:
    def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
        slots1.sort()
        slots2.sort()

        s1, s2 = len(slots1), len(slots2)
        i1, i2 = 0, 0
        while i1 < s1 and i2 < s2:
            start = max(slots1[i1][0], slots2[i2][0])
            end = min(slots1[i1][1], slots2[i2][1])
            if end - start >= duration:
                return [start, start + duration]
            else:
                if slots1[i1][1] < slots2[i2][1]:
                    i1 += 1
                else:
                    i2 += 1
        return []


if __name__ == "__main__":
    # [60,68]
    print(Solution().minAvailableDuration(slots1=[[10, 50], [60, 120], [140, 210]], slots2=[[0, 15], [60, 70]],
                                          duration=8))

    # []
    print(Solution().minAvailableDuration(slots1=[[10, 50], [60, 120], [140, 210]], slots2=[[0, 15], [60, 70]],
                                          duration=12))
